package edu.nctu.csie.jichang.dp.behavioral;

public class State {
	public static void main(String[] args) {
		CurrentState tCurrentState = new CurrentState();
		tCurrentState.current = new StateOpen();
		tCurrentState.show();
		tCurrentState.changeState();
		tCurrentState.show();
		tCurrentState.changeState();
		tCurrentState.show();
	}
}
class CurrentState{
	AbstractState current;
	void changeState(){current.changeState(this);}
	void show() {System.out.println(current.name);}
}
abstract class AbstractState{
	String name;
	AbstractState(String name){this.name = name;}
	abstract void changeState(CurrentState state);
}
class StateOpen extends AbstractState{
	StateOpen() {super("Open State");}
	void changeState(CurrentState state) {state.current = new StateRead();}
}
class StateRead extends AbstractState{
	StateRead() {super("Read State");}
	void changeState(CurrentState state) {state.current = new StateClose();}
}
class StateClose extends AbstractState{
	StateClose() {super("Close State");}
	void changeState(CurrentState state) {state.current = new StateOpen();}
}
